<template>
  <div>
    <ul>
      <li
        v-for="item in treeData"
        :key="item.name"
        @click="clickI(item.name, $event)"
      >
        {{ item.name }}
        <xy-tree
          v-if="item.child && item.child.length > 0"
          :tree-data="item.child"
          @changeI="clickI"
        ></xy-tree>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'xyTree',
  props: { treeData: { type: Array, default: Array } },
  methods: {
    clickI(i, event) {
      if (event) {
        event.stopPropagation() // 阻止事件冒泡
      }
      this.$emit('changeI', i)
    },
  },
}
</script>

<style scoped></style>
